package com.baomidou;

import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.converts.MySqlTypeConvert;
import com.baomidou.mybatisplus.generator.config.querys.MySqlQuery;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.keywords.MySqlKeyWordsHandler;
import com.google.common.collect.ImmutableMap;
import org.apache.commons.io.FileUtils;
import org.jeecg.modules.lims.biz.common.base.BaseLogicDomain;

import java.io.File;
import java.io.IOException;

public class CodeGeneratorMain {

    public static void main(String[] args) throws IOException {
        //全局配置
        String dir = "D:\\tmp\\code";
        File directory = new File(dir);
        FileUtils.cleanDirectory(directory);
        GlobalConfig config = new GlobalConfig.Builder()
                .outputDir(dir)
                .author("xm")
                .enableSwagger()
                .commentDate("yyyy-MM-dd HH:ss:mm")
                .enableSwagger()
                .build();
        //数据源配置
        DataSourceConfig dataSourceConfig = new DataSourceConfig
                .Builder("jdbc:mysql://192.168.5.238:3306/dcore-lims?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai",
                "root"
                , "Szch@2023")
                .dbQuery(new MySqlQuery())
                .schema("mybatis-plus")
                .typeConvert(new MySqlTypeConvert())
                .keyWordsHandler(new MySqlKeyWordsHandler())
                .build();
        //策略配置
        StrategyConfig strategyConfig =new StrategyConfig.Builder()
                .addInclude("dl_experiment_reservation")
                .addTablePrefix(
                        "dl_"
                )
                .entityBuilder()
                .superClass(BaseLogicDomain.class)
                .disableSerialVersionUID()
                .enableChainModel()
                .enableLombok()
                .enableTableFieldAnnotation()
                .naming(NamingStrategy.underline_to_camel)
                .columnNaming(NamingStrategy.underline_to_camel)
                .formatFileName("%sDo")
                .build();
        //包名策略配置
        PackageConfig packageConfig = new PackageConfig.Builder()
                .parent("org.jeecg.modules.lims.biz")
                .entity("domain")
                .service("service")
                .serviceImpl("service.impl")
                .mapper("mapper")
                .xml("mapper.xml")
                .controller("controller")
                .build();
        //整合配置
        packageConfig.setRequestAddBeanPackage("org.jeecg.modules.lims.api.pojo.dto.request");
        packageConfig.setRequestSearchBeanPackage("org.jeecg.modules.lims.api.pojo.dto.request");
        packageConfig.setResponseDetailBeanPackage("org.jeecg.modules.lims.api.pojo.dto.response");
        packageConfig.setShortPackage("dangerous");
        packageConfig.setRequestMappingMap(
                ImmutableMap.<String, String>of(
                        "dl_equipment_claim_return", "/equipment/claim-return"
                )
        );
        packageConfig.setI18ErrorMap(
                ImmutableMap.<String, String>of(
                        "dl_equipment_claim_return", "equipment-claim-return"
                )
        );

        AutoGenerator autoGenerator = new AutoGenerator(dataSourceConfig);
        autoGenerator.global(config)
                .strategy(strategyConfig)
                .packageInfo(packageConfig);


        //6.执行
        autoGenerator.execute();
    }
}
